package rpc

import (
	"context"

	gpbv1 "goTong/api/order/v1"
	"goTong/gtong/registry"
	"goTong/gtong/server/rpcserver"
	"goTong/gtong/server/rpcserver/clientinterceptors"
)

const orderServiceName = "discovery:///gotong-order-srv"

func NewOrderServiceClient(r registry.Discovery) gpbv1.OrderClient {
	conn, err := rpcserver.DialInsecure(
		context.Background(),
		rpcserver.WithEndpoint(orderServiceName),
		rpcserver.WithDiscovery(r),
		rpcserver.WithClientUnaryInterceptor(clientinterceptors.UnaryTracingInterceptor),
	)
	if err != nil {
		panic(err)
	}
	c := gpbv1.NewOrderClient(conn)
	return c
}
